package com.zeratul.common.mybatis.core.page.utils;


import com.zeratul.common.core.context.DataContextHolde;
import com.zeratul.common.mybatis.core.page.entity.Page;

import static com.zeratul.common.core.constant.ContextConstants.PAGE_CONTEXT_KEY;

/**
 * Page对象缓存的ThreadLocal工具类
 */
public class ZtPages {

    /*
    分页相关的方法
     */
    public static Page getPage(){
        return DataContextHolde.getReqData(PAGE_CONTEXT_KEY);
    }

    public static void setPage(Integer pageNum, Integer pageSize, boolean isBatch){
        Page page = new Page();
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        page.setEnable(!isBatch);
        DataContextHolde.setReqData(PAGE_CONTEXT_KEY, page);
    }

    public static void setPage(Integer pageNum, Integer pageSize) {
        ZtPages.setPage(pageNum, pageSize, false);
    }

    public static void clearPage(){
        DataContextHolde.removeReqData(PAGE_CONTEXT_KEY);
    }
}
